package com.exam.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ExamManage;
import com.exam.entity.Zhi;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ZhiManageMapper {
    @Select("select * from zhi")
    List<Zhi> findAll();

    @Select("select * from zhi")
    IPage<Zhi> findAll(Page page);

    @Select("select * from zhi where id = #{id}")
    Zhi findById(Integer id);

    @Delete("delete from zhi where id = #{id}")
    int delete(Integer id);

    @Update("update zhi set main = #{main}"+
            " where id = #{id}")
    int update(Zhi z);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into zhi(subject,course,main)" +
            " values(#{subject},#{course},#{main})")
    int add(Zhi zhi);
    @Select("select * from zhi where subject = #{sub} and course = #{course}")
    IPage<Zhi> findBySub(Page<Zhi> page, String sub, Integer course);

    /**
     * 查询最后一条记录的paperId,返回给前端达到自增效果
     * @return paperId
     */
//    @Select("select paperId from exam_manage order by paperId desc limit 1")
//    ExamManage findOnlyPaperId();
}
